package com.example.fragment.tool;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class MyDataBaseHelper extends SQLiteOpenHelper {//1.新建类继承SQLiteOpenHelper

    private Context context;//上下文

    //数据库中创建一张Student表
    public static final String Test = "create table Test ("
            + "id integer primary key autoincrement," + "a1 text,"
            + "a2 text," + "a3 text,"+ "a4 text," + "a5 text,"+ "a6 text,"  + "a7 text)";
    //数据库中创建一张Student表
    public static final String Person = "create table Person ("
            + "id integer primary key autoincrement," + "a1 text,"
            + "a2 text," + "a3 text,"+ "a4 text," + "a5 text,"+ "a6 text,"  + "a7 text)";
    //数据库中创建一张Student表
    public static final String  Plan1= "create table Plan1 ("
            + "id integer primary key autoincrement," + "a1 text,"
            + "a2 text," + "a3 text,"+ "a4 text," + "a5 text,"+ "a6 text,"  + "a7 text)";


    //2.实现构造方法
    public MyDataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        //int version-当前数据库的版本号，可用于对数据库进行升级操作
        super(context, name, factory, version);
        this.context = context;
    }


    //3.重写onCreate方法
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(Test);//执行建表语句，创建数据库
        sqLiteDatabase.execSQL(Person);
        sqLiteDatabase.execSQL(Plan1);
        Toast.makeText(context,"Create succeeded",Toast.LENGTH_SHORT).show();
    }

    //4.重写onUpgrade方法
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }

}
